package com.example.dnfgamercommunitybackend.service.impl;

import com.example.dnfgamercommunitybackend.dao.ReplyCommentDao;
import com.example.dnfgamercommunitybackend.entity.ReplyComment;
import com.example.dnfgamercommunitybackend.entity.ResponseResult;
import com.example.dnfgamercommunitybackend.service.ReplyCommentService;
import com.example.dnfgamercommunitybackend.util.DfaUtil;
import com.example.dnfgamercommunitybackend.util.JwtUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

@Service
public class ReplyCommentServiceImpl implements ReplyCommentService {
    @Resource
    private ReplyCommentDao replyCommentDao;
    @Resource
    private JwtUtil jwtUtil;
    @Resource
    private DfaUtil dfaUtil;
    @Override
    public String addReplyComment(ReplyComment replyComment, String authorization) {
        if (StringUtils.hasText(replyComment.getContent())){
            if (dfaUtil.textFilter(replyComment.getContent())){
                replyComment.setAccountId(Integer.parseInt(jwtUtil.getUserIdFromToken(authorization)));
                if (replyCommentDao.addReplyComment(replyComment) > 0){
                    return ResponseResult.successStringResult("回复成功");
                }
            }
            return ResponseResult.failureStringResult(505,"评论内容不合法，请修改");
        }
        return ResponseResult.failureStringResult(504,"回复失败");
    }

    @Override
    public String deleteReplyComment(int replyCommentId) {
        if (replyCommentDao.deleteReplyComment(replyCommentId) > 0){
            return ResponseResult.successStringResult("删除成功");
        }
        return ResponseResult.failureStringResult(504,"删除失败");
    }
}
